﻿using OkTool.Regex;
using System;
using System.Collections.Generic;
using System.Text;

namespace OkTool.Util
{
    public class PhoneUtil
    {
        /// <summary>
        /// 验证是否为手机号码(中国大陆)
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool IsMobile(string value)
        {
            return RegexUtil.IsMatch(value,RegexPool.MOBILE);
        }

        /// <summary>
        /// 隐藏手机号前7位  替换字符为"*"
        /// </summary>
        /// <param name="phone"></param>
        /// <returns></returns>
        public static string HideBefore(string phone)
        {
            return StrUtil.Hide(phone, 0, 7);
        }

        /// <summary>
        /// 隐藏手机号中间4位  替换字符为"*"
        /// </summary>
        /// <param name="phone"></param>
        /// <returns></returns>
        public static string HideBetween(string phone)
        {
            return StrUtil.Hide(phone, 3, 7);
        }

        /// <summary>
        /// 隐藏手机号最后4位  替换字符为"*"
        /// </summary>
        /// <param name="phone"></param>
        /// <returns></returns>
        public static string HideAfter(string phone)
        {
            return StrUtil.Hide(phone, 7, 11);
        }

        /// <summary>
        /// 获取手机号前3位
        /// </summary>
        /// <param name="phone"></param>
        /// <returns></returns>
        public static string SubBefore(string phone)
        {
            return StrUtil.Sub(phone, 0, 3);
        }

        /// <summary>
        /// 获取手机号中间4位
        /// </summary>
        /// <param name="phone"></param>
        /// <returns></returns>
        public static string SubBetween(string phone)
        {
            return StrUtil.Sub(phone, 3, 7);
        }

        /// <summary>
        /// 获取手机号后4位
        /// </summary>
        /// <param name="phone"></param>
        /// <returns></returns>
        public static string SubAfter(string phone)
        {
            return StrUtil.Sub(phone, 7, 11);
        }
    }
}
